*Import the intermediary data
*import delimited "\\adsroot.itcs.umich.edu\home\hursre\Documents\Papers\Evangelical Signalling\Data\RawData\Data_Intermediary.csv", clear 
***********************************************************************
* Change certain string variables to numeric so regressions will run **
***********************************************************************
g prop_1=0
replace prop_1=1 if prop=="TRUE"
drop prop
rename prop_1 prop
tab prop

g doutor_1=0
replace doutor_1=1 if doutor=="TRUE"
drop doutor
rename doutor_1 doutor
tab doutor

g title_1=0
replace title_1=1 if title=="TRUE"
drop title
rename title_1 title
tab title

***********************************************************************************************
* Generating and labelling some dummies to make it easier to create summary statistics chart **
***********************************************************************************************
* Mayor and Vice Mayor
gen mayor=0
gen vicemayor=0
replace mayor=1 if cargocode==11
replace vicemayor=1 if cargocode==12
* Gender
gen female=0
replace female=1 if sex=="FEMALE"
label var female "Female"
gen male=0
replace male=1 if sex=="MALE"
label var male "Male"
gen badsex=0
replace badsex=1 if sex=="999"
label var badsex "Sex Unreported or Miscoded"
* Education
gen edu1=0
replace edu1=1 if eduname==1
label var edu1 "Less than Middle School"
gen edu2=0
replace edu2=1 if eduname==2
label var edu2 "Middle School"
gen edu3=0
replace edu3=1 if eduname==3
gen edu4=0
replace edu4=1 if eduname==4
label var edu4 "Some College"
gen edu5=0
replace edu5=1 if eduname==999
label var edu5 "Education Unreported or Miscoded"
* Party
gen pdt=0
replace pdt=1 if party=="PDT"
label var pdt "Democratic Labor Party"
gen psdb=0
replace psdb=1 if party=="PSDB"
label var psdb "Brazilian Social Democrat Party"
gen pt=0
replace pt=1 if party=="PT"
label var pt "Workers Party"
gen ptb=0
replace ptb=1 if party=="PTB"
label var ptb "Brazilian Labor Party"
gen pmdb=0
replace pmdb=1 if party=="PMDB"
label var pmdb "Brazilian Democratic Movement Party"
gen other=0
replace other=1 if pdt==0 & psdb==0 & pt==0 & ptb==0 & pmdb==0 
label var other "Other Party"
encode party, generate(party1)
drop party
rename party1 party
tab party
* Catholic titles
g cath=0
g frei1=0
g padre1=0
replace frei1=1 if frei=="TRUE"
replace padre1=1 if padre=="TRUE"
replace cath=1 if padre1==1 | frei1==1
tab cath

******************************************
* Some final cleaning steps on the data **
******************************************
* Rescale population variable so it fits better in the summary stats table
replace population=population/1000
* Defining variables over which I'll define fixed effects
egen lcode_year = group(lcode year)
egen candidateid = group(id lcode)
* Add interaction variable that will be useful in creating marginsplots later on
gen interaction = 0
replace interaction = prop*anyevan 
* Creating 'bins' on the anyevan variable to make Figures 1 and 2
gen bins = .
replace bins =0 if anyevan <= 0.1 
replace bins =1 if anyevan > 0.10 & anyevan <= 0.15 
replace bins =2 if anyevan > 0.15 & anyevan <= 0.20 
replace bins =3 if anyevan > 0.20 & anyevan <= 0.25 
replace bins =4 if anyevan > 0.25 & anyevan <= 0.30 
replace bins =5 if anyevan > 0.30 
* Changing a variable name from Portuguese to English
rename doutor doctor
* Only keep variables actually used in the paper
keep title prop doctor bins interaction mayor vicemayor female reljob eduname edu1 edu2 edu3 edu4 pdt psdb pt ptb pmdb other population /// 
     anyevan cath win thresh year lcode candidateid party raceid lcode_year candidateid timerun numcandidates ballot name jobname municipality everreljob

* Save 
save "\\adsroot.itcs.umich.edu\home\hursre\Documents\Papers\Evangelical Signalling\Paper Drafts\JOP\Replication_Material\Data.dta", replace




 




